import React from "react";
import { Button } from "antd";
const ExportJsonExcel = require("js-export-excel");

type Props = {};

export default function Export({}: Props) {
  const handleExport = () => {
    // 直接导出文件

    var option: any = {}; //导出文件相关配置

    option.fileName = "轮播图数据"; //导出的文件名

    option.datas = [
      //配置excel表格内部数据，一个对象为一张表
      {
        sheetData: [
          //数据包
          { one: "一行一列", two: "一行二列", img: "img.png" },
          { one: "二行一列", two: "二行二列", img: "img.png" },
        ],
        sheetName: "sheet",
        sheetFilter: ["img", "two", "one"], //控制每一列中需要渲染的字段
        sheetHeader: ["第一列", "第二列"], //每一列的头部标题信息
        columnWidths: [20, 20],
      },
      {
        sheetData: [
          { one: "一行一列", two: "一行二列" },
          { one: "二行一列", two: "二行二列" },
        ],
      },
    ];

    var toExcel = new ExportJsonExcel(option); //new
    toExcel.saveExcel(); //保存
  };
  return (
    <div>
      <Button onClick={handleExport}>导出Excel</Button>
    </div>
  );
}
